import {
  Body,
  Controller,
  DefaultValuePipe,
  Get,
  Inject,
  Param,
  ParseIntPipe,
  Post,
  Query,
} from '@nestjs/common';
import { BookingService } from './booking.service';
import { RequireLogin, RequirePermission } from 'src/decorator/index.decorator';
import { ChangeBookingDto } from 'src/dto/ChangeBooking.dto';

@Controller('booking')
@RequireLogin()
export class BookingController {
  @Inject(BookingService)
  private readonly bookingService: BookingService;

  @Get('list')
  async getBookingList(
    @Query('pageNum', new DefaultValuePipe(1), ParseIntPipe)
    pageNum: number,
    @Query('pageSize', new DefaultValuePipe(99999), ParseIntPipe)
    pageSize: number,
    @Query('username') username: string,
    @Query('roomName') roomName: string,
    @Query('roomLocation') roomLocation: string,
    @Query('startTime') startTime: string,
    @Query('endTime') endTime: string,
  ) {
    return await this.bookingService.getBookingList(
      pageNum,
      pageSize,
      username,
      roomName,
      roomLocation,
      startTime,
      endTime,
    );
  }

  @Post('changeStatus')
  @RequirePermission('manage_booking')
  async changeBookingStatus(@Body() changeBookingDto: ChangeBookingDto) {
    return await this.bookingService.changeBookingStatus(changeBookingDto);
  }

  @Get('cancelBooking/:id')
  async cancelBooking(@Param('id', ParseIntPipe) id: number) {
    return this.bookingService.cancelBooking(id);
  }

  @Get('urge/:id')
  async urge(@Param('id', ParseIntPipe) id: number) {
    return this.bookingService.urge(id);
  }
}
